﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using System.Collections.ObjectModel;
using ShivamEMR.Model.Domain.UserDomain;
using ShivamEMR.Model.Domain.UIDomain;
using ShivamEMR.Model.Domain.PersonDomain;
using ShivamEMR.Model.Domain.CompanyDomain;

namespace ShivamEMR.Model.Domain
{
    public class ShivamEMRInitializer : /*DropCreateDatabaseIfModelChanges<ShivamEMRContext>  //*/ DropCreateDatabaseAlways<ShivamEMRContext>
    {
        protected override void Seed(ShivamEMRContext context)
        {
            var  male = new PersonDomain.Sex() { SexName = "Male" };
            context.Sexes.Add(male);
            context.Sexes.Add(new PersonDomain.Sex() { SexName="Female" });
            var pstatus = new PersonDomain.PersonStatus() { Status="Active" };
            context.PersonStatus.Add(pstatus);
            var prole = new PersonDomain.PersonRole() { Role = "Doctor" };
            context.PersonRoles.Add(new PersonDomain.PersonRole() { Role = "Employee" });
            context.PersonRoles.Add(new PersonDomain.PersonRole() { Role = "Patient" });
            context.PersonRoles.Add(prole);

            context.PersonStages.Add(new PersonStage() { Stage="NewBorn" });
            context.PersonStages.Add(new PersonStage() { Stage = "Child" });
            context.PersonStages.Add(new PersonStage() { Stage = "Teen" });
            context.PersonStages.Add(new PersonStage() { Stage = "Adult" });
            context.PersonStages.Add(new PersonStage() { Stage = "Old" });

            context.MaritalStatus.Add(new MaritalStatus() { Status="Married" });
            context.MaritalStatus.Add(new MaritalStatus() { Status = "Single" });
            context.MaritalStatus.Add(new MaritalStatus() { Status = "Divorced" });

            context.EmployeeStatus.Add(new EmployeeStatus() { Status="Active" });
            context.EmployeeStatus.Add(new EmployeeStatus() { Status = "Suspended" });
            context.EmployeeStatus.Add(new EmployeeStatus() { Status = "Inactive" });
            context.EmployeeStatus.Add(new EmployeeStatus() { Status = "Deleted" });

            context.SaveChanges();
            //base.Seed(context);
            //var dr = new DoctorsDomain.Doctor() { EmpCode = "D1", DrNotes = "", Title = "Mr.", FirstName = "John", LastName = "guthry", MiddleName = "M",
            //    DateOfBirth = DateTime.Now, DateOfJoin = DateTime.Now, Sex = male,
            //    PersonStatus = pstatus };
          
            //dr.MaritalStatus = context.MaritalStatus.First();
            
            //dr.PersonRoles = new List<PersonDomain.PersonRole>();
            //dr.PersonRoles.Add(prole);
            //context.Doctors.Add(dr);

            //context.Accounts.Add(new AccountsDomain.Account() {
            //    Taxes = new ObservableCollection<AccountsDomain.Tax>() { 
            //    new AccountsDomain.Tax(){  }
            //    } as ICollection<AccountsDomain.Tax> });

            var menurighttype = new UserRightType() { Type = "Menu" };
            var actionrighttype = new UserRightType() { Type = "ActionMethod" };
                var controllerrighttype=new UserRightType() { Type = "Controller" };
            context.UserRightTypes.Add(menurighttype);
            context.UserRightTypes.Add(actionrighttype);
            context.UserRightTypes.Add(controllerrighttype);

            //var registerright = new UserDomain.UserRight() { RightTitle = "RegisterPatient", Type = menurighttype };
            //var admissionright = new UserDomain.UserRight() { RightTitle = "PatientAdmission", Type = menurighttype };
            //context.UserRights.Add(registerright);
            //context.UserRights.Add(admissionright);
            //var appointmentright = new UserDomain.UserRight() { RightTitle = "Appointment", Type = menurighttype };
            //context.UserRights.Add(new UserDomain.UserRight() { RightTitle = "PatientDischarge", Type = menurighttype });
            //context.UserRights.Add(appointmentright);
            //var assignmentright = new UserDomain.UserRight() { RightTitle = "Assignment", Type = menurighttype };
            //context.UserRights.Add(assignmentright);
            //var billingright = new UserDomain.UserRight() { RightTitle = "Billing", Type = menurighttype };
            //context.UserRights.Add(billingright);

            context.UserRoles.Add(new UserRole() { Role="Admin" });
            context.UserRoles.Add(new UserRole() { Role = "Simple" });

            //var mgroup=new MenuGroup() { Group="DoctorDashboard" };
            //var pgroup=new MenuGroup(){ Group="Patient" };
            //pgroup.Menus = new List<Menu>();
            //pgroup.Menus.Add(new Menu() { Title="Registration", Link="patient/patient/registration" , Right=registerright});
            //pgroup.Menus.Add(new Menu() { Title = "Admission", Link = "patient/patient/admission" , Right=admissionright});            
            //pgroup.Menus.Add(new Menu() { Title = "Billing", Link = "patient/patient/billing" , Right=billingright});
            //pgroup.Menus.Add(new Menu() { Title = "Appointments", Link = "patient/patient/appointments" , Right=appointmentright});
            ////pgroup.Menus.Add(new Menu() { Title = "Reports", Link = "patient/patient/reports" });
            ////pgroup.Menus.Add(new Menu() { Title = "Services", Link = "patient/patient/services" });
            ////pgroup.Menus.Add(new Menu() { Title = "followups", Link = "patient/patient/followups" });
            ////var dgroup=new MenuGroup(){ Group="Doctor" };
            //pgroup.Menus.Add(new Menu() { Title = "queue", Link = "patient/patient/queue" });
            //pgroup.Menus.Add(new Menu() { Title = "assignments", Link = "patient/patient/assignments" });
            //pgroup.Menus.Add(new Menu() { Title = "schedule", Link = "patient/patient/schedule" });
            
            // var rgroup=new MenuGroup(){ Group="Reports" };
          //   mgroup.Children = new List<MenuGroup>();
          //   mgroup.Children.Add(pgroup);
          ////   mgroup.Children.Add(dgroup);
          ////   mgroup.Children.Add(rgroup);
          //   context.MenuGroups.Add(mgroup);

            //var emp=new Employee(){ FirstName="Dushyant", LastName="Nagar", MiddleName="kumar", DateOfBirth=DateTime.Parse("12/6/1985"), Sex=male };
            //emp.MaritalStatus=context.MaritalStatus.First();
            //context.Employees.Add(emp);

             //var person = new Person() { ID = new Guid(), Title = "Mr.", FirstName = "Dushyant", LastName = "Nagar", MiddleName = "kumar", DateOfBirth = DateTime.Parse("12/6/1985"), Sex = male };
             //person.MaritalStatus = context.MaritalStatus.First();
             //person.PersonRoles = new List<PersonRole>();
             //person.PersonRoles.Add(prole);
             //person.PersonStatus = pstatus;
             //context.People.Add(person);
             //context.SaveChanges();

             var emp = new Employee() {  Title = "Mr.", FirstName = "Vikas", LastName = "Jain", MiddleName = "kumar", DateOfBirth = DateTime.Parse("11/6/1980"), Sex = male };
             emp.DateOfJoin = DateTime.Now.AddYears(-10);
             emp.MaritalStatus = context.MaritalStatus.First();
             emp.PersonRoles = new List<PersonRole>();
             emp.PersonRoles.Add(prole);
             emp.EmployeeStatus = context.EmployeeStatus.First();
             emp.PersonStatus = pstatus;
             context.Employees.Add(emp);


            context.SaveChanges();
        }
    }
}
